import schedule from '@blueos.app.appmanager.schedule'
import utils from './utils'


export default {
    scheduleJob(data,callback){
      let tmpRemindTime = data.remindTime.replace(" ", "T")
      let bt = new Date(tmpRemindTime).getTime()
      let now = new Date().getTime()
      //let diff = 0.5 * 60 * 1000
      let diff = bt - now
      if(diff <= 0){
        callback({
          code : 0,
          msg : "时间已过"
        })
        return
      }
      utils.log("--begin time = " + bt + ",end time = " + now +',diff = ' + diff)
      utils.log("data.id = " + data.id)
      schedule.scheduleJob({
        type: 2,
        timeout: diff,
        triggerMethod: 'scheduleFunc',
        params: { 
          id: data.id,
        },
        success: function (data) {
          callback({
            code : 1,
            id : data.id
          })
        },
        fail: function (data, code) {
          callback({
            code : 0,
            msg : "未知错误"
          })
        },
        complete: function () {
          console.log(`handling complete`)
        },
      })
    }
  
  }
  
